package com.ha.web.controller.system.salary.controller;

import java.util.List;
import org.apache.shiro.authz.annotation.RequiresPermissions;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Controller;
import org.springframework.ui.ModelMap;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.PathVariable;
import org.springframework.web.bind.annotation.PostMapping;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.ResponseBody;
import com.ha.common.annotation.Log;
import com.ha.common.enums.BusinessType;
import com.ha.system.salary.domain.HaEmployeeSalary;
import com.ha.system.salary.service.IHaEmployeeSalaryService;
import com.ha.common.core.controller.BaseController;
import com.ha.common.core.domain.AjaxResult;
import com.ha.common.utils.poi.ExcelUtil;
import com.ha.common.core.page.TableDataInfo;

/**
 * 员工薪资Controller
 * 
 * @author admin
 * @date 2021-03-17
 */
@Controller
@RequestMapping("/salary/salary")
public class HaEmployeeSalaryController extends BaseController
{
    private String prefix = "salary/salary";

    @Autowired
    private IHaEmployeeSalaryService haEmployeeSalaryService;

    @RequiresPermissions("salary:salary:view")
    @GetMapping()
    public String salary()
    {
        return prefix + "/salary";
    }

    /**
     * 查询员工薪资列表
     */
    @RequiresPermissions("salary:salary:list")
    @PostMapping("/list")
    @ResponseBody
    public TableDataInfo list(HaEmployeeSalary haEmployeeSalary)
    {
        startPage();
        List<HaEmployeeSalary> list = haEmployeeSalaryService.selectHaEmployeeSalaryList(haEmployeeSalary);
        return getDataTable(list);
    }

    /**
     * 导出员工薪资列表
     */
    @RequiresPermissions("salary:salary:export")
    @Log(title = "员工薪资", businessType = BusinessType.EXPORT)
    @PostMapping("/export")
    @ResponseBody
    public AjaxResult export(HaEmployeeSalary haEmployeeSalary)
    {
        List<HaEmployeeSalary> list = haEmployeeSalaryService.selectHaEmployeeSalaryList(haEmployeeSalary);
        ExcelUtil<HaEmployeeSalary> util = new ExcelUtil<HaEmployeeSalary>(HaEmployeeSalary.class);
        return util.exportExcel(list, "salary");
    }

    /**
     * 新增员工薪资
     */
    @GetMapping("/add")
    public String add()
    {
        return prefix + "/add";
    }

    /**
     * 新增保存员工薪资
     */
    @RequiresPermissions("salary:salary:add")
    @Log(title = "员工薪资", businessType = BusinessType.INSERT)
    @PostMapping("/add")
    @ResponseBody
    public AjaxResult addSave(HaEmployeeSalary haEmployeeSalary)
    {
        return toAjax(haEmployeeSalaryService.insertHaEmployeeSalary(haEmployeeSalary));
    }

    /**
     * 修改员工薪资
     */
    @GetMapping("/edit/{id}")
    public String edit(@PathVariable("id") Long id, ModelMap mmap)
    {
        HaEmployeeSalary haEmployeeSalary = haEmployeeSalaryService.selectHaEmployeeSalaryById(id);
        mmap.put("haEmployeeSalary", haEmployeeSalary);
        return prefix + "/edit";
    }

    /**
     * 修改保存员工薪资
     */
    @RequiresPermissions("salary:salary:edit")
    @Log(title = "员工薪资", businessType = BusinessType.UPDATE)
    @PostMapping("/edit")
    @ResponseBody
    public AjaxResult editSave(HaEmployeeSalary haEmployeeSalary)
    {
        return toAjax(haEmployeeSalaryService.updateHaEmployeeSalary(haEmployeeSalary));
    }

    /**
     * 删除员工薪资
     */
    @RequiresPermissions("salary:salary:remove")
    @Log(title = "员工薪资", businessType = BusinessType.DELETE)
    @PostMapping( "/remove")
    @ResponseBody
    public AjaxResult remove(String ids)
    {
        return toAjax(haEmployeeSalaryService.deleteHaEmployeeSalaryByIds(ids));
    }
}
